<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>数据库</title>
    <link rel="stylesheet" href="css/main.css" type="text/css">
    <script src="js/jquery-3.1.1.min.js"></script>
    <script src="js/common.js" ></script>
</head>
<body style="background-color: lavender;">
<form class="basic-form register" style="height: 450px;width: 450px;">
    <label><span><cite class="red">*</cite>用户名：</span><input name="id" type="text" /></label>
    <br>
    <label><span><cite class="red">*</cite>昵称：</span><input name="name" type="text" /></label>
    <br>
    <label><span><cite class="red">*</cite>密码：</span><input name="pwd" type="password" /></label>
    <br>
    <label>
        <span>性别：</span>
        <select name="male" >
            <option value="">保密</option>
            <option value="0">男</option>
            <option value="1">女</option>
        </select>
    </label>
    <br>
    <label><span>年龄：</span><input name="age" type="number" step="1" min="0" max="100" /></label>
    <br>
    <a onclick="register()">注册</a>
    <a style="margin-left: 10px;" href="login.html">跳转登录</a>
</form>
</body>
<script>
var register = function () {
    var datas = {};
    $('form [name]').each(function (e,v) {
        datas[$(v).attr('name')] = $(v).val();
    });
    $.ajax({
        type:'POST',
        url:cm.params.postUrl+'register',
        data:datas,
        success:function(result){
            var values = JSON.parse(result);
            if(values.err){
                alert(values.err);
            }else{
                alert('注册成功，准备跳转到登录页面');
                window.location.href = 'login.html';
            }
        },
        error:function (msg) {
            console.log(msg);
        }
    });
}
</script>
</html>